/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "score/scoredbestof.h"
#include <iostream>

using namespace std;
using namespace bol;

/**
 *A singleton class with two dummy names...
 */
class TwoScoresDescriptor: public MetaScoreDescriptor{
  private:
    static TwoScoresDescriptor* _instance;
    TwoScoresDescriptor(const char* names[], const int n):MetaScoreDescriptor(names, n){};
    ;

  public:

    static TwoScoresDescriptor* instance(){
      if(_instance==NULL){
        const char*n[]={"val_1", "val_2"};
        _instance=new TwoScoresDescriptor(n, 2);
      }
      return _instance;
    }

};
TwoScoresDescriptor* TwoScoresDescriptor::_instance=NULL;

class TwoScores: public MetaScore{
  private:
  public:
    //here the implemented constructor defines the values (although in practice these values could be set later)
    TwoScores(const double v1, const double v2):MetaScore(TwoScoresDescriptor::instance()){
      set(0, v1);
      set(1, v2);
    }
    // implements the pure virtual method
    double mainScore()const{
      //cerr<<"score="<<(*this)[0]<<endl;
      return value(0);
    }

};
  typedef boost::shared_ptr<TwoScores> TwoScoresPtr;

class TwoScoreObject:public HasMetaScore{
  private:
    const string m_string;
    TwoScoresPtr m_score;
  public:
    TwoScoreObject(const string s, const double d1, const double d2):m_string(s){
      m_score=TwoScoresPtr(new TwoScores(d1, d2));
    }
    ~TwoScoreObject(){
      cerr<<"deleting ["<<m_string<<"]"<<endl;
    }
    MetaScorePtr score()const{
      return m_score;
    }

};
  typedef boost::shared_ptr<TwoScoreObject> TwoScoreObjectPtr;

int main(int argc, char **argv){
  MetaScore *s1=new TwoScores(2, 1.2);
  cout<<(*s1)<<endl;

  vector<MetaScore*>vScores;
  vScores.push_back(new TwoScores(2, 1));
  vScores.push_back(new TwoScores(3, 2));
  vScores.push_back(new TwoScores(1, 3));
  vScores.push_back(new TwoScores(3, 4));
  vScores.push_back(new TwoScores(1.7, 5));
  sort(vScores.begin(), vScores.end(), MetaScore::ltPtr);
  for(vector<MetaScore*>::const_iterator it=vScores.begin(); it<vScores.end(); ++it){
    cout<<(**it)<<endl;
  }

  //test scoredBestOf
  ScoredBestOf bestof(3);
  vector<TwoScoreObjectPtr>vObj;
  bestof.add(TwoScoreObjectPtr(new TwoScoreObject("a", 1, 2)));
  bestof.add(TwoScoreObjectPtr(new TwoScoreObject("b", 2, 3)));
  bestof.add(TwoScoreObjectPtr(new TwoScoreObject("c", 2, 3)));
  bestof.add(TwoScoreObjectPtr(new TwoScoreObject("d", 3, 3)));
  bestof.add(TwoScoreObjectPtr(new TwoScoreObject("e", 1, 3)));
  

  cout<<bestof;
  
  return 0;
}
